{% extends "zato/index.html" %}

{% block html_title %}Endpoint topics{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">

    <style type="text/css">
         table.vertical-align-middle td {
            vertical-align: middle;
         }
    </style>

{% endblock %}

{% block "extra_js" %}

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.tablesorter.min.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>

    <script nonce="{{ CSP_NONCE }}">
    $.fn.zato.data_table.get_columns = function() {
        return [
            '_numbering',
            '_topic',
            '_time',
            '_msg_id',
            '_ext_client_id',
            '_data',
        ]
    }
    </script>

{% endblock %}

{% block "content" %}
<h2 class="zato">
    Topics last published to by endpoint : <a href="{% url "pubsub-endpoint" %}?cluster={{ cluster_id }}&amp;query={{ endpoint.name }}">{{ endpoint.name }}</a>
    : Type :
    {{ client_html|safe }}
</h2>

{% if not zato_clusters %}
    {% include "zato/no-clusters.html" %}
{% else %}

    {% if cluster_id %}

        <div id="markup">
            <table id="data-table" class="vertical-align-middle">
                <thead>
                    <tr class='ignore'>
                        <th style="width:5%">&nbsp;</th>
                        <th><a href="#">Topic</a></th>
                        <th><a href="#">Pub time</a></th>
                        <th><a href="#">Msg ID</a></th>
                        <th><a href="#">Ext. client ID</a></th>
                        <th><a href="#">Data</a></th>
                </thead>

                <tbody>
                {% if items %}
                {% for item in items %}
                    <tr class="{% cycle 'odd' 'even' %}" id='tr_{{ item.topic_id }}'>
                        <td class='numbering'>&nbsp;</td>
                        <td>
                            <a href="{% url "pubsub-topic" %}?cluster={{ cluster_id }}&amp;query={{ item.topic_name }}">{{ item.topic_name }}</a>
                        </td>
                        <td style="width:20%">

                            <a
                                id="a_pub_time_{{ item.pub_msg_id }}"
                                href="javascript:$.fn.zato.toggle_time('pub_time_{{ item.pub_msg_id }}', '{{ item.pub_time }}', '{{ item.pub_time_utc }}')">{{ item.pub_time }}
                            </a>

                            {% if item.ext_pub_time %}
                                <br/>
                                <a
                                    id="a_ext_pub_time_{{ item.pub_msg_id }}"
                                    href="javascript:$.fn.zato.toggle_time('ext_pub_time_{{ item.pub_msg_id }}', '{{ item.ext_pub_time }}', '{{ item.ext_pub_time_utc }}')">{{ item.ext_pub_time }}
                                </a>

                            {% endif %}

                        </td>
                        <td>
                            {% if item.pub_correl_id or item.in_reply_to %}
                                    id:{{ item.pub_msg_id }}

                                {% if item.pub_correl_id %}
                                    <br/>
                                    cid:{{ item.pub_correl_id }}
                                {% endif %}

                                {% if item.in_reply_to %}
                                    <br/>
                                    in-reply-to:{{ item.in_reply_to }}
                                {% endif %}

                            {% else %}
                                {{ item.pub_msg_id }}
                            {% endif %}
                        </td>
                        <td>
                            {% if item.ext_client_id %}
                                {{ item.ext_client_id }}
                            {% else %}
                                <span class="form_hint">---</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if item.data %}
                                <textarea style="height:60px;width:100%">{{ item.data }}</textarea>
                            {% else %}
                                <span class="form_hint">---</span>
                            {% endif %}
                        </td>
                {% endfor %}
                {% else %}
                    <tr class='ignore'>
                        <td colspan='6'>No results</td>
                    </tr>
                {% endif %}

                </tbody>
            </table>
        </div>

{% include "zato/paginate/action-panel.html" %}

    {% endif %} {% comment %}cluster_id{% endcomment %}

{% endif %}{% comment %}not zato_clusters{% endcomment %}

{% endblock %}
